package com.zhp.web;

import com.zhp.pojo.HOrder;
import com.zhp.pojo.HUser;
import com.zhp.pojo.HUserinfo;
import com.zhp.service.OrderService;
import com.zhp.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @Author Lone Ranger
 */
@WebServlet("/showOrder")
public class ShowOrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        HUser hUser = (HUser) session.getAttribute("u");
        HUserinfo ui = hUser.getUi();
        OrderService orderService = new OrderServiceImpl();

        List<HOrder> orders = orderService.findOrderByUdid(ui.getDid());

        req.setAttribute("os", orders);
        req.getRequestDispatcher("/info.jsp").forward(req, resp);
    }
}
